<template>
  <div>
    <el-row>
      <Ca-tree centerName="加盟分供方"
               @nodeClick="nodeClick"></Ca-tree>
      <el-col :span="21"
              style="padding-left:20px;">
        <el-form inline
                 size="mini">
          <el-form-item label="姓名">
            <el-input v-model="username"
                      clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button-group>
              <el-button type="primary"
                         @click="query">查询</el-button>
              <el-button type="primary"
                         @click="isopenwin">新增</el-button>
              <el-button type="primary"
                         @click="joinproject">加盟项目</el-button>
              <el-button type="primary"
                         @click="getSummary">汇总</el-button>
            </el-button-group>
          </el-form-item>
        </el-form>
        <Ca-rule-table :DataList="WorkerList"
                       :header="header"
                       :headle="headle"
                       @checkleave="editItem"></Ca-rule-table>
        <paging :currentpage="currentpage"
                :currentlimit="currentlimit"
                :total="total"
                @setpage="getpage"
                @setlimit="getlimit"></paging>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="isopen"
               width="70%"
               v-dialogDrag>
      <modify-window @close="close"
                     :roleList="roleList"
                     :userList="userList"
                     :submitType="submitType"></modify-window>
    </el-dialog>
    <el-dialog :visible.sync="isopenJoin"
               top="8vh"
               width="60%"
               v-dialogDrag>
      <project-operation-com :companyId="3"
                             openType="Business"></project-operation-com>
    </el-dialog>
    <el-dialog :visible.sync="isopenSum"
               width="80%"
               v-dialogDrag
               top="8vh">
      <summary-table v-if="isopenSum"> </summary-table>
    </el-dialog>
  </div>
</template>

<script>
import projectOperationCom from "@/components/project-operation/project-operation-com";
import CaTree from "@/components/Ca-tree/Ca-tree";
import ModifyWindow from "./components/modify-window";
import {
  apiworkerUserList,
  apiworkerUserNew,
  apiProjectSummary
} from "@/request/api";
//汇总
import SummaryTable from "./components/summary-table";
export default {
  name: "materialDepaInfor",
  data () {
    return {
      currentpage: 1,
      currentlimit: 15,
      username: "",
      WorkerList: [],
      header: [
        ["工号", "user_num", 80],
        ["姓名", "username", 100],
        ["电话号码", "phone_number", 120],
        ["性别", "sex2", 80],
        ["邮箱", "email", 160],
        ["公司", "company_name", 110],
        ["中心", "center_name", 110],
        ["部门", "department_name", 110],
        ["身份证号码", "user_card", 180],
        ["身份证地址", "card_address", 270]
      ],
      headle: ["编辑"],
      isopen: false,
      userList: [],
      submitType: "",
      roleList: [],
      isopenJoin: false,
      total: 0,
      isopenSum: false
    };
  },
  components: {
    ModifyWindow,
    CaTree,
    projectOperationCom,
    SummaryTable
  },
  created () {
    this.getWorkerList();
  },
  methods: {
    // 汇总
    getSummary () {
      this.isopenSum = true;
      // apiProjectSummary({year:'2017'}).then(res=>{
      //   console.log(res)
      // })
    },
    query () {
      this.currentlimit = 15;
      this.currentpage = 1;
      this.getWorkerList();
    },
    close () {
      this.isopen = false;
      this.getWorkerList();
    },
    nodeClick (data) {
      if (data.name != "分供方") {
        this.currentpage = 1;
        this.currentlimit = 15;
        this.getWorkerList();
      }
    },
    //获取工人职位信息
    getWorkerpost () {
      apiworkerUserNew().then(res => {
        res.roles.forEach(item => {
          this.roleList.push([item.role_id, item.role_name]);
        });
      });
    },
    editItem (row) {
      console.log(row);
      this.userList = [row];
      if (this.roleList == "") {
        this.getWorkerpost();
      }
      this.isopen = true;
      this.submitType = "";
    },
    isopenwin () {
      if (this.roleList == "") {
        this.getWorkerpost();
      }
      this.userList = [
        {
          company_id: 17,
          center_id: 39,
          center_name: "加盟分供方",
          company_name: "分供方"
        }
      ];
      this.isopen = false;
      this.$nextTick(() => {
        this.isopen = true;
      });
      this.submitType = "new";
    },
    getpage (val) {
      this.currentpage = val;
      this.getWorkerList();
    },
    getlimit (val) {
      this.currentlimit = val;
      this.getWorkerList();
    },
    //所有材料部信息
    getWorkerList () {
      let data = {
        rows: this.currentlimit,
        page: this.currentpage,
        username: this.username,
        center_name: "加盟分供方"
      };
      apiworkerUserList(data).then(res => {
        console.log(res);
        this.total = res.total;
        this.WorkerList = res.rows.map(item => {
          item.sex2 = item.sex == 1 ? "男" : "女";
          return item;
        });
      });
    },
    joinproject () {
      this.isopenJoin = true;
    }
  }
};
</script>

<style lang="scss"></style>
